/*
 * Licensed under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.submarine.startup;

import org.submarine.common.Constants;
import org.submarine.config.ConfigUtil;
import org.submarine.exchange.Agent;
import org.submarine.exchange.Collector;

/**
 * 
 * @file org.submarine.startup.Bootstrap.java
 *
 * 启动入口
 * 
 * @author gaojian
 * @created 2013-8-17 下午11:09:04
 * @version 0.0.1
 * @since 0.0.1
 *
 */
public final class Bootstrap {
	
	/**
	 * 
	 * 启动入口
	 *
	 * @author gaojian
	 * @created 2013-8-17 下午11:09:17
	 *
	 */
	public static void main(String[] args) {
		if (Constants.AGENT_APPLICATION_SIDE.equals(ConfigUtil.getProperty(Constants.APPLICATION_SIDE_KEY))) {
			final Agent agent = new Agent();
			agent.start();
			synchronized (Bootstrap.class) {
				while (agent.isRunning()) {
					try {
						Bootstrap.class.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		} else {
			final Collector collector = new Collector();
			collector.start();
			synchronized (Bootstrap.class) {
				while (collector.isRunning()) {
					try {
						Bootstrap.class.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}

}
